package com.zhijian.warehouse.manage.entity.vo.response;

import com.zhijian.util.BeanUtil;
import com.zhijian.warehouse.manage.enums.ProductEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 盘点产品明细表 回显vo
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-27 13:58:00
 */
@Data
@Api(tags = "盘点产品明细表回显vo")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StoreStockRecordProductVo implements Serializable {

    private static final long serialVersionUID = -1;

    /**
     * 主键ID
     */
    @ApiModelProperty("主键ID")
    private Long id;

    /**
     * 盘点单ID
     */
    @ApiModelProperty("盘点单ID")
    private Long storeStockRecordId;

    /**
     * 产品ID
     */
    @ApiModelProperty("产品ID")
    private Long productId;

    /**
     * 盘点数
     */
    @ApiModelProperty("盘点数")
    private BigDecimal stockCount;

    /**
     * 盘点数
     */
    @ApiModelProperty("库存数量")
    private BigDecimal storeCount;

    /**
     * 仓库ID
     */
    @ApiModelProperty("仓库ID")
    private Long warehouseId;

    /**
     * 仓库ID
     */
    @ApiModelProperty("库位ID")
    @NotNull(message = "库位ID不能为空")
    private Long warehouseLocationId;

    /**
     * 创建时间
     */
    @ApiModelProperty("创建时间")
    private String createTime;

    /**
     * 修改时间
     */
    @ApiModelProperty("修改时间")
    private String updateTime;

    @ApiModelProperty("产品名称")
    private String productName;
    @ApiModelProperty("产品编码")
    private String productNumber;
    @ApiModelProperty("产品rfid码")
    private String productRfId;
    @ApiModelProperty("产品型号")
    private String productModel;
    @ApiModelProperty("产品备注")
    private String productNote;
    @ApiModelProperty("产品 状态，1：正常，2：故障，3：作废")
    private Byte productStatus;
    @ApiModelProperty("产品 状态 字符串")
    private String productStatusStr;
    @ApiModelProperty("发卡状态，1：已发卡，0：未发卡")
    private Byte productCardStatus;
    @ApiModelProperty("发卡状态字符串")
    private String productCardStatusStr;
    @ApiModelProperty("品类")
    private String categoryName;
    @ApiModelProperty("单位名称")
    private String unitName;
    @ApiModelProperty("库位")
    private String warehouseLocationName;

    private String productIdLocationId;


    @ApiModelProperty("亏盈数")
    private BigDecimal deficitNumber;

    /**
     * APP 盘盈产品数
     */
    @ApiModelProperty("APP 盘盈产品数")
    private BigDecimal profitProductCount;
    /**
     * APP 盘亏产品数
     */
    @ApiModelProperty("APP 盘亏产品数")
    private BigDecimal lossesProductCount;


    public BigDecimal getDeficitNumber(){
        if(this.stockCount == null || this.storeCount == null){
            return null;
        }
        return this.stockCount.subtract(this.storeCount);
    }

    public String getProductIdLocationId() {
        return String.format("%s_%s", this.warehouseLocationId,this.productId );
    }

    public String getProductCardStatusStr() {
        if (BeanUtil.isNotEmpty(this.productCardStatus) && ProductEnum.StatusEnum.getByCode(Integer.valueOf(this.productCardStatus)) != null)
            return ProductEnum.StatusEnum.getByCode(Integer.valueOf(this.productCardStatus)).getDesc();
        return productCardStatusStr;
    }

    public String getProductStatusStr() {
        if (BeanUtil.isNotEmpty(this.productStatus) && ProductEnum.StatusEnum.getByCode(Integer.valueOf(this.productStatus)) != null)
            return ProductEnum.StatusEnum.getByCode(Integer.valueOf(this.productStatus)).getDesc();
        return productStatusStr;
    }
}